﻿<%@ Page Title="回货计划" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
    <link href="../assets/css/plugins/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />
    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link href="../assets/css/system/pageDefault.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <%-- 按钮--%>
            <div class="btns-container"></div>
            <%--新增弹出框begin--%>
            <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content animated bounceInRight">
                        <div class="modal-header">
                            <span class="editTitle"></span>
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span> <span class="sr-only">关闭</span> </button>
                        </div>
                        <div id="message" style="display: none"></div>
                        <div class="modal-body clearfix">
                            <form class="form-horizontal">
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class="control-label input-sm">供应商:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_ShortName" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class="control-label input-sm">仓库:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_StockName" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">订单号:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_OrderBillNo" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">货号名称:</label>
                                    </div>
                                    <div class="col-sm-6 ">
                                        <input type="text" id="text_MaterialShortName" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class="control-label input-sm">货号:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_MaterialID" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">到货日期:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_StartShipDate" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">到货数量:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_RemainQty" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">调整后到货日期:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_AdjustStartShipDate" name="text_AdjustStartShipDate" datacol="yes" err="调整后到货日期" checkexpession="NotNull" maxlength="10" class="form-control required input-sm" />
                                        <input type="text" id="text_OldAdjustStartShipDate" name="text_OldAdjustStartShipDate" class="hide" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class="control-label input-sm">调整后到货数量:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_AdjustRemainQty" name="text_AdjustRemainQty" placeholder="" datacol="yes" err="调整后到货数量" checkexpession="NotNull" maxlength="10" class="form-control required input-sm" />
                                        <input type="text" id="text_OldAdjustRemainQty" name="text_OldAdjustRemainQty" placeholder="" class="hide" />
                                    </div>
                                </div>
                            </form>
                            <br />
                        </div>
                        <div class="modal-footer">
                            <button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
                            <button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
            <%--新增弹出框end--%>
            <%--查询条件begin--%>
            <div class="condition-container" style="overflow: visible;">
                <form class="form-horizontal">
                    <div class="row">
                        <div class="form-group col-xs-3">
                            <label for="search-Area" class="control-label">供应商</label>
                            <select id="search-ShortNames" class="form-control selectpicker" data-width="150px" data-style="backselect" data-live-search="true" multiple></select>
                        </div>
                        <div class="form-group col-xs-3">
                            <label for="search-Kind" class="control-label">大类</label>
                            <select id="search-KindNames" class="form-control selectpicker " data-width="150px" data-style="backselect" data-live-search="true" multiple></select>
                        </div>
                        <div class="form-group col-xs-3">
                            <label for="search-Item" class="control-label">子项</label>
                            <select id="search-ItemNames" class="form-control selectpicker" data-width="150px" data-style="backselect" data-live-search="true" multiple></select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label" style="float: left">货号</label>
                            <div style="width: 160px; float: left; margin-left: 3px;">
                                <div class="input-group text-center">
                                    <input type="text" class="form-control" placeholder="多个用','分隔" id="search-MaterialIDs">
                                    <div class="input-group-btn no-padding">
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="tips">
                    <i class="fa fa-lightbulb-o"></i>
                    计划到货日期/调整后到货日期为红色时表示超时；计划到货数量/调整后到货数量为橙色时表示ERP订单有部分已回货； 每天08:30系统自动获取最新回货数据！
                </div>
            </div>
            <%--查询条件end--%>
            <div class="table-container">
                <table class="table table-bordered  table-select tableReturPlan"></table>
            </div>
        </div>
    </div>

</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/jquery-ui-1.10.4.min.js"></script>
    <script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
    <script src="../assets/js/plugins/bootstrap-suggest/bootstrap-suggest.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-suggest/itemSuggest.js"></script>


    <script src="../assets/js/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-select/bootstrap-select.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>


    <script src="../assets/js/plugins/jQuery-DataTables/media/js/jquery.dataTables.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/media/js/dataTables.bootstrap.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/bootstrap-table-nm.js"></script>

    <script>
        $('document').ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                $('#editBtn').attr("disabled", "disabled");
                rScroll();
            });

            var q_shortNames = "", q_kindNames = "", q_itemNames = "", temp_values;

            var loadParam = {
                ShortNames: '',
                KindNames: '',
                ItemNames: '',
                MaterialIDs: ''
            }

            var setLoadParam = function () {
                loadParam.ShortNames = q_shortNames;
                loadParam.KindNames = q_kindNames;
                loadParam.ItemNames = q_itemNames;
                loadParam.MaterialIDs = $('#search-MaterialIDs').val()
            }

            var SetQueryValues = function () {
                q_shortNames = q_kindNames = q_itemNames = "";
                temp_values = $('#search-ShortNames').val();
                if (temp_values != "" && temp_values != null) {
                    q_shortNames = temp_values.join(',');
                }
                temp_values = $('#search-KindNames').val();
                if (temp_values != "" && temp_values != null) {
                    q_kindNames = temp_values.join(',');
                }
                temp_values = $('#search-ItemNames').val();
                if (temp_values != "" && temp_values != null) {
                    q_itemNames = temp_values.join(',');
                }
                setLoadParam();
            }

            //供应商
            var nmGetShortNames = function (els, size, callback) {
                nmCommonBindList('ReturPlan', 'GetShortNames', {}, els, 'VendCustID', 'ShortName', size, callback);
            }
            //大类
            var nmGetKindInfo = function (els, size, callback) {
                nmCommonBindList('Common', 'GetKindInfo', {}, els, 'KindID', 'KindName', size, callback);
            }
            //子项
            var nmGetItemInfo = function (els, params, size, callback) {
                nmCommonBindList('Common', 'GetItemInfo', { kindIds: params }, els, 'ItemorSub', 'ItemorSub', size, callback);
            }


            //货号
            var nmGetMaterialIDs = function () {
                SetQueryValues();
                var param = {
                    ShortNames: q_shortNames,
                    KindNames: q_kindNames,
                    ItemNames: q_itemNames
                }
                var itemSuggest_MaterialIDs = new itemSuggest();
                itemSuggest_MaterialIDs.destroy();
                itemSuggest_MaterialIDs.SetBtnHide();
                itemSuggest_MaterialIDs.initSuggestPram('search-MaterialIDs', 'ReturPlan', 'GetMaterials', 'MaterialID', 'MaterialID', param);
            }

            //初始化表格
            nmGetShortNames(['#search-ShortNames']);
            nmGetKindInfo(['#search-KindNames']);
            nmGetItemInfo(['#search-ItemNames']);
            nmGetMaterialIDs();

            //大类获取小类
            $(document).on("change", "#search-KindNames", function () {
                //console.log("触发了原生的change事件!");
                $("#search-ItemNames").html('<option value="">请选择</option>');
                var ids = $(this).val();
                if (ids == "" || ids == null) {
                    return;
                }
                nmGetItemInfo(['#search-ItemNames'], ids.join(',')); //小品类
                nmGetMaterialIDs();
            });

            $(document).on("change", "#search-ItemNames", function () {
                nmGetMaterialIDs();
            });

            $('#text_AdjustStartShipDate').datepicker({
                format: "yyyy-mm-dd",
                language: "zh-CN",
                autoclose: true,
                todayHighlight: true,
                startDate: new Date()
            });

            //只能输入数字
            $('#text_AdjustRemainQty').bind('input propertychange', function () {

                var myReg = /^[\u4e00-\u9fa5]+$/;
                if (myReg.test($(this).val())) {
                    $(this).val("");
                }
                if (isNaN($(this).val())) {
                    $(this).val($(this).val().substring(0, $(this).val().length - 1));
                    return;
                }
                //将中文替换掉
                $(this).val($(this).val().replace(/[^\x00-\xff]/g, ''));

                //最多为9999家
                if (parseInt($(this).val()) > 10000) {
                    $(this).val($(this).val().substring(0, $(this).val().length - 1));
                    return
                }
            });

            var columns = [
                { title: "供应商", data: "ShortName", width: "100px", className: "ShortName" },
                { title: "仓库", width: '130px', data: "StockName", className: "StockName" },
                { title: "订单号", width: '150px', data: "OrderBillNo", className: "OrderBillNo" },
                { title: "货品名称", width: '200px', data: "MaterialShortName", className: "MaterialShortName" },
                { title: "货号", width: "120px", data: "MaterialID", className: "MaterialID" },
                { title: "订单数量", width: "50px", data: "Qty", className: "Qty" },
                {
                    title: "计划<br/>到货日期", width: "80px", data: "StartShipDate", className: "StartShipDate",
                    render: function (data, type, full, meta) {
                        var html = (data == null ? ' ' : new Date(data).format('yyyy-MM-dd'));
                        if (full.ChangeFlag == 2) {
                            html = '<span class="font-red">' + html + '</span >';
                        }
                        return html;
                    }
                },
                {
                    title: "订单<br/>剩余数量", width: "50px", data: "RemainQty", className: "RemainQty",
                    render: function (data, type, full, meta) {
                        var html = data == null ? ' ' : data;
                        if (full.ChangeFlag == 1) {
                            html = '<span class="font-yellow">' + html + '</span >';
                        }
                        return html;
                    }
                },
                {
                    title: "调整后<br/>到货日期", width: "80px", data: "AdjustStartShipDate", className: "AdjustStartShipDate",
                    render: function (data, type, full, meta) {
                        var html = (data == null ? ' ' : new Date(data).format('yyyy-MM-dd'));
                        if (full.ChangeFlag == 2) {
                            if (full.AdjustStartShipDate != null) {
                                var adjustStartShipDate = new Date(full.AdjustStartShipDate)
                                if (adjustStartShipDate > new Date()) {
                                    html = '<span class="font-red">' + html + '</span >';
                                }
                            }
                        }
                        return html;
                    }
                },
                {
                    title: "调整后<br/>到货数量", width: "80px", data: "AdjustRemainQty", className: "AdjustRemainQty",
                    render: function (data, type, full, meta) {
                        var html = data == null ? ' ' : data;
                        if (full.ChangeFlag == 1) {
                            html = '<span class="font-yellow">' + html + '</span >';
                        }
                        return html;
                    }
                }
            ];

            SetQueryValues();
            //表格初始化
            dataTable.initTable('.table', 'ReturPlan', 'GetReturPlanList', loadParam, columns);

            IsCreate = true;
            //获取列表
            var loadList = function () {
                $('#editBtn').attr('disabled', 'disabled');
                SetQueryValues();
                dataTable.loadList(loadParam);
            }

            //查询按钮
            $('.btns-container').on('click', '#btn-search', function () {
                loadList();
            });

            //获取Erp数据
            $('.btns-container').on('click', '#btn_queryErpData', function () {
                page = 1;
                layer.msg('获取ERP数据……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('ReturPlan', 'SyncReturPlanByERP', {}, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal("获取成功!", '', 'success');
                        //刷新列表
                        loadList()
                    }
                });
            });

            //编辑按钮
            $('.btns-container').on('click', '#editBtn', function () {
                $('.editTitle').text('编辑数据');
                $('#addModuleBtn').show();
                resetInput();
                IsCreate = false;
                loadDetail();
            });

            var resetInput = function () {
                $('#text_ShortName').val("");
                $('#text_OrderBillNo').val("");
                $('#text_MaterialShortName').val("");
                $('#text_MaterialID').val("");
                $('#text_StartShipDate').val("");
                $('#text_RemainQty').val("");
                $('#text_AdjustStartShipDate').val("");
                $('#text_AdjustRemainQty').val("");
                $('#text_OldAdjustStartShipDate').val("");
                $('#text_OldAdjustRemainQty').val("");
            }

            var ShortName, OrderBillNo, MaterialShortName, MaterialID, StartShipDate, RemainQty, AdjustStartShipDate, AdjustRemainQty, StockName;

            //选中按钮信息
            $('.tableReturPlan tbody').on('click', 'tr', function () {
                ShortName = $(this).find('.ShortName').text();
                StockName = $(this).find('.StockName').text();
                OrderBillNo = $(this).find('.OrderBillNo').text();
                MaterialShortName = $(this).find('.MaterialShortName').text();
                MaterialID = $(this).find('.MaterialID').text();
                StartShipDate = $(this).find('.StartShipDate').text();
                RemainQty = $(this).find('.RemainQty').text();
                AdjustStartShipDate = $(this).find('.AdjustStartShipDate').text();
                AdjustRemainQty = $(this).find('.AdjustRemainQty').text();
                //解除禁止编辑和删除按钮
                if (OrderBillNo != null && OrderBillNo != '') {
                    $('#editBtn').removeAttr('disabled');
                }
            });

            //获取选中行的内容,填充到打开的框内
            var loadDetail = function () {
                //有的会加载出来两个 
                if (OrderBillNo == "") {
                    swal("数据异常，订单编号不能为空，请刷新页面重试", '', 'error');
                    return false;
                }
                /*
                赋值
                */
                $('#text_ShortName').val(ShortName);
                $('#text_StockName').val(StockName);
                $('#text_OrderBillNo').val(OrderBillNo);
                $('#text_MaterialShortName').val(MaterialShortName);
                $('#text_MaterialID').val(MaterialID);
                $('#text_StartShipDate').val(StartShipDate);
                $('#text_RemainQty').val(RemainQty);
                $('#text_AdjustStartShipDate').val(AdjustStartShipDate);
                $('#text_AdjustRemainQty').val(AdjustRemainQty);

                //保存旧的
                $('#text_OldAdjustStartShipDate').val(AdjustStartShipDate);
                $('#text_OldAdjustRemainQty').val(AdjustRemainQty);
            }

            //弹窗的保存操作
            $('#addModuleBtn').click(function () {
                if (!CheckDataValid('.form-horizontal')) {
                    return false;
                }
                var action = "";
                var successText = "";
                if (IsCreate) {
                    action = "Insert";
                    successText = '新增成功';
                    $('#ShopPlanID').val("0");
                }
                else {
                    action = "Update";
                    successText = '编辑成功';
                    //效验是否未更改内容
                    if (CheckIsChang()) {
                        tipCss($(this), "数据未更改"); return false;
                    }
                }
                if ($('#ShopNum').val() <= 0) {
                    tipCss($(this), "数量不能小于零"); return false;
                }


                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('ReturPlan', action, {
                    OrderBillNo: $('#text_OrderBillNo').val(),
                    MaterialID: $('#text_MaterialID').val(),
                    AdjustStartShipDate: $('#text_AdjustStartShipDate').val(),
                    AdjustRemainQty: $('#text_AdjustRemainQty').val()
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal(successText, '', 'success');
                        //关闭新建  or 编辑框  
                        $('#closeAddBox').click();
                        //刷新列表
                        loadList();
                    }
                });
            });
            //修改时 验证是否有修改内容
            var CheckIsChang = function () {
                if ($('#text_AdjustStartShipDate').val() == 0) {
                    return false;
                }

                if ($('#text_AdjustRemainQty').val() == 0) {
                    return false;
                }
                var OldAdjustStartShipDate = $('#text_OldAdjustStartShipDate').val();
                var OldAdjustRemainQty = $('#text_OldAdjustRemainQty').val();

                var AdjustStartShipDate = $('#text_AdjustStartShipDate').val();
                var AdjustRemainQty = $('#text_AdjustRemainQty').val();

                if (OldAdjustStartShipDate == AdjustStartShipDate && OldAdjustRemainQty == AdjustRemainQty)
                    return true;
                return false;
            }
        });
    </script>
</asp:Content>



